package com.doudou.collection.infrastructure.core.config;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;

/**
 * @ClassName ValidationConfiguration<br>
 * @Description Validation配置类<br>
 * @Author 李浩文<br>
 * @Date 2023/6/15 21:47<br>
 * @Version 1.0<br>
 */
@Slf4j
@Configuration
public class ValidationConfig {

    public ValidationConfig() {
        log.debug("创建配置类对象：ValidationConfig");
    }

    @Bean
    public Validator validator() {
        return Validation.byProvider(HibernateValidator.class)
                .configure() // 开始配置
                .failFast(true) // 配置快速失败
                .buildValidatorFactory() // 构建Validator工厂
                .getValidator(); // 从Validator工厂中获取Validator对象
    }

}
